#include "btform.h"
#include "ui_btform.h"
#include <QPixmap>
#include <QRect>

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);

    ui->linebox->hide();
    line1Animal = new QPropertyAnimation(ui->line1,"geometry",this);
    line1Animal->setDuration(1500); //设置动画持续的时⻓
    line1Animal->setKeyValueAt(0,QRect(9,26,2,0));  //根据value创建关键帧
    line1Animal->setKeyValueAt(0.5,QRect(9,9,2,17));
    line1Animal->setKeyValueAt(1,QRect(9,26,2,0));
    line1Animal->setLoopCount(-1);  //设置动画的循环次数-1是无限循环
    line1Animal->start();

    line2Animal = new QPropertyAnimation(ui->line2,"geometry",this);
    line2Animal->setDuration(1600); //设置动画持续的时⻓
    line2Animal->setKeyValueAt(0,QRect(14,26,2,0));  //根据value创建关键帧
    line2Animal->setKeyValueAt(0.5,QRect(14,9,2,17));
    line2Animal->setKeyValueAt(1,QRect(14,26,2,0));
    line2Animal->setLoopCount(-1);  //设置动画的循环次数-1是无限循环
    line2Animal->start();

    line3Animal = new QPropertyAnimation(ui->line3,"geometry",this);
    line3Animal->setDuration(1700); //设置动画持续的时⻓
    line3Animal->setKeyValueAt(0,QRect(19,26,2,0));  //根据value创建关键帧
    line3Animal->setKeyValueAt(0.5,QRect(19,9,2,17));
    line3Animal->setKeyValueAt(1,QRect(19,26,2,0));
    line3Animal->setLoopCount(-1);  //设置动画的循环次数-1是无限循环
    line3Animal->start();

    line4Animal = new QPropertyAnimation(ui->line4,"geometry",this);
    line4Animal->setDuration(1800); //设置动画持续的时⻓
    line4Animal->setKeyValueAt(0,QRect(24,26,2,0));  //根据value创建关键帧
    line4Animal->setKeyValueAt(0.5,QRect(24,9,2,17));
    line4Animal->setKeyValueAt(1,QRect(24,26,2,0));
    line4Animal->setLoopCount(-1);  //设置动画的循环次数-1是无限循环
    line4Animal->start();
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::seticon(QString btIcon, QString content, int mid)
{
    // 设置⾃定义按钮的图⽚、⽂字、以及id
    ui->bticon->setPixmap(QPixmap(btIcon));
    ui->bttext->setText(content);
    this->id = mid;
}

void BtForm::clearBg()
{
    // 清除上⼀个按钮点击的背景效果,恢复之前的样式
    ui->btstyle->setStyleSheet("#btstyle:hover{ background:#D8D8D8;} ");
}

void BtForm::clearlinebox()
{
    ui->linebox->hide();
}

int BtForm::getid()
{
    return id;
}

void BtForm::showAnimal(bool isshow)
{
    // 显⽰linebox, 设置颜⾊为绿⾊
    if(isshow)
    {
        ui->linebox->show();
    }
    else
    {
        ui->linebox->hide();
    }

}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    // 让编译器不要触发警告
    (void)event;
    // ⿏标点击之后，背景变为绿⾊，⽂字变为⽩⾊
    ui->btstyle->setStyleSheet("#btstyle{ background:rgb(30,206,154);}*{color:#F6F6F6;}");
    ui->linebox->show();
    emit click(this->id);       // 发送⿏标点击信号
}
